package it4s.service.api.google.core;

import java.io.IOException;


import it4s.service.api.factory.GoogleFactoryInstance;
import it4s.service.api.factory.GoogleInstance;
import it4s.service.api.factory.IServiceInstance;

import com.google.api.services.plus.Plus;
import com.google.api.services.plus.model.Activity;

public class OperationGoogle {

	private Plus plus;

	public OperationGoogle() {
		IServiceInstance instance = null;
		GoogleInstance googleInstance = (GoogleInstance) new GoogleFactoryInstance()
				.createServiceInstance(instance);
		if (googleInstance != null) {
			plus = googleInstance.getPlus();
		}
	}

	/** Get an activity for which we already know the ID. */
	public  void getActivity() throws IOException {
		// A known public activity ID
		String activityId = "z12gtjhq3qn2xxl2o224exwiqruvtda0i";
		// We do not need to be authenticated to fetch this activity
		header1("Get an explicit public activity by ID");
		Activity activity = plus.activities().get(activityId).execute();
		show(activity);
	}

	private void header1(String name) {
		System.out.println();
		System.out
				.println("================== " + name + " ==================");
		System.out.println();
	}

	private void show(Activity activity) {
		System.out.println("id: " + activity.getId());
		System.out.println("url: " + activity.getUrl());
		System.out.println("content: " + activity.getObject().getContent());
	}

}
